﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WPFExcelReport.Helpers;
using System.Collections;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class TVKGAAUF
    { 
        public TVKGAAUF()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VGAAUF();
            this.DataContext = MV; 
            InitializeComponent();
     
        } 
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        { 
            base.vwMaster_CurrentChanged(sender, e);
            
        }

        private void txtKRS_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                QueryCommand(null, null);
            }
        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            if (POS == "000")
            {
                POS = "001";
            }
            dwData = TBMain.NewRow(); 
            dwData["GAAUFKRS"] = KRS;
            dwData["GAAUFLFD"] = LFD;
            dwData["GAAUFPOS"] = POS; 
            try
            {
                SResult = ((VGAAUF)MV).QueryGAAUF(dwData, 25);
                MergeData(SResult,true);
            } 
            catch (Exception ex)
            {
                    Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void LOADBYAUF()
        {
            if (ORDERNUM.Length < 12)
                return;
            TBMain.Clear();
            KRS = ORDERNUM.Substring(1, 2);
            LFD = ORDERNUM.Substring(3, 6);
            //POS = ORDERNUM.Substring(9, 3); 
            dwData = TBMain.NewRow();
            dwData["GAAUFKRS"] = KRS;
            dwData["GAAUFLFD"] = LFD;
            dwData["GAAUFPOS"] = "001"; 
            try
            {
                SResult = ((VGAAUF)MV).QueryGAAUF(dwData, 25);
                MergeData(SResult,false);
            } 
            catch (Exception ex)
            {
                    Tracer.Error(ex.StackTrace, ex);
            }
        }
            
    }
}
